package mybs;

import java.util.Arrays;

/**
 * http://topic.csdn.net/u/20091229/20/b4a664bf-c493-4253-b7c4-09108a6287f7.html
 * http://bbs.db001.com/viewthread.php?tid=485
 * http://forum.byr.edu.cn/article/ACM_ICPC/40699
 * http://blog.csdn.net/fanhj__2007/archive/2010/04/29/5542389.aspx
 * 
 * @author HaHa
 *
 */
public class SubArray {
	public static int[] numAry = new int[] { 1, 1, 2, 2, 3, 4};
	public static int[] flagAry = new int[10];

	public static int searchNum = 5;
	
	public static void Portfolio(int n, int p) {
		int num = 0;
		String str = null;
		for (int i = n; i >= p; i--) {
			System.out.println(Arrays.toString(flagAry));
			flagAry[p] = numAry[i - 1];
			if (p > 1)
				Portfolio(i - 1, p - 1);
			else {
				num = 0;
				str = "";
				for (int j = flagAry[0]; j > 0; j--) {
					str = str + flagAry[j];
					num = num + flagAry[j];
				}
			}
			if (num == searchNum)
				System.out.println(str);
		}
	}

	// 调用
	public static void call() {
		for (int i = 1; i <= numAry.length; i++) {
			flagAry[0] = i;
			Portfolio(numAry.length, i);
		}
	}

	public static void main(String[] args) {
		SubArray.call();
	}

}
